<?php
require_once ('config.php');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>注册</title>
<link href="style.css" rel="stylesheet" type="text/css" />
<script language="javascript">
function chk(theForm){
	if (theForm.user.value.replace(/(^\s*)|(\s*$)/g, "") == ""){
		alert("帐号不能为空！");
		theForm.user.focus();   
		return (false);   
	}		
	
	if (theForm.password.value.replace(/(^\s*)|(\s*$)/g, "") == ""){
		alert("密码不能为空！");
		theForm.password.focus();   
		return (false);   
	}	
	
	if (theForm.password.value != theForm.pass.value){
		alert("两次输入密码不一样！");
		theForm.pass.focus();   
		return (false);   
	}	
		 
	if (theForm.name.value.replace(/(^\s*)|(\s*$)/g, "") == "" || theForm.name.value.replace(/[\u4e00-\u9fa5]/g, "")){
		alert("真实姓名不能为空且必须为中文！");   
		theForm.name.focus();   
		return (false);   
	}
}
</script>
<?php
if($_POST["submit"]){
if(empty($_POST['user']))
	echo "<script>alert('帐号不能为空');location='reg.php';</script>";
else if(empty($_POST['password']))
	echo "<script>alert('密码不能为空');location='reg.php';</script>";
else if($_POST['password']!=$_POST['pass'])
	echo "<script>alert('两次密码不一样');location='reg.php';</script>";
else if(!empty($_POST['qq'])&&!is_numeric($_POST['qq']))
	echo "<script>alert('qq号必须全为数字');location='reg.php';</script>";
else if(!empty($_POST['phone'])&&!is_numeric($_POST['phone']))
	echo "<script>alert('手机号码必须全为数字');location='reg.php';</script>";
else if(!empty($_POST['email'])&&!ereg("([0-9a-zA-Z]+)([@])([0-9a-zA-Z]+)(.)([0-9a-zA-Z]+)",$_POST['email']))
	echo "<script>alert('邮箱输入不合法');location='reg.php';</script>";
else{
$_SESSION['member']=$_POST['user'];
$sql="insert into member values('','".$_POST['user']."','".md5($_POST['password'])."','".$_POST['name']."','".$_POST['sex']."','".$_POST['qq']."','".$_POST['phone']."','".$_POST['email']."')";
$result=mysql_query($sql)or die(mysql_error());
if($result)
echo "<script>alert('恭喜你注册成功,马上进入主页面');location='my.php';</script>";
else
{
	echo "<script>alert('注册失败');location='reg.php';</script>";
	mysql_close();
}
	}
}
?>
</head>
<body>
<form id="theForm" name="theForm" method="post" action="" onSubmit="return chk(this)" runat="server" style="margin-bottom:0px;">
  <table width="450" border="0" align="center" cellpadding="5" cellspacing="1" bgcolor="#B3B3B3">
    <tr>
      <td colspan="2" align="left" bgcolor="#EBEBEB">会员注册&nbsp;&nbsp;以下打“*”为必填项</td>
    </tr>
    <tr>
      <td width="120" align="right" bgcolor="#FFFFFF">账&nbsp;&nbsp;&nbsp;号:</td>
      <td width="817" bgcolor="#FFFFFF"><input name="user" type="text" id="user" size="20" maxlength="20" />
	  <font color="#FF0000"> *</font>(由数字或字母组成)</td>
    </tr>
    <tr>
      <td align="right" bgcolor="#FFFFFF">密&nbsp;&nbsp;&nbsp;码:</td>
      <td bgcolor="#FFFFFF"><input name="password" type="password" id="password" size="20" maxlength="20" />
      <font color="#FF0000"> *</font>(由数字或字母组成)</td>
    </tr>
    <tr>
      <td align="right" bgcolor="#FFFFFF">确认密码:</td>
      <td bgcolor="#FFFFFF"><input name="pass" type="password" id="pass" size="20" />
      <font color="#FF0000"> *</font>(再次输入密码)</td>
    </tr>
    <tr>
      <td align="right" bgcolor="#FFFFFF">真实姓名:</td>
      <td bgcolor="#FFFFFF"><input name="name" type="text" id="name" size="20" />
      <label><font color="#FF0000">*</font></label></td>
    </tr>
    <tr>
      <td align="right" bgcolor="#FFFFFF">性&nbsp;&nbsp;&nbsp;别:</td>
      <td align="left" bgcolor="#FFFFFF">
          <input name="sex" type="radio" id="0" value="男" checked="checked" />
          男
          <input type="radio" name="sex" value="女" id="1" />
          女&nbsp;
		</td>
    </tr>
    <tr>
      <td align="right" bgcolor="#FFFFFF">Q&nbsp;&nbsp;&nbsp;Q:</td>
      <td bgcolor="#FFFFFF"><input name="qq" type="text" id="qq" size="20"/></td>
    </tr>
    <tr>
      <td align="right" bgcolor="#FFFFFF">联系方式:</td>
      <td bgcolor="#FFFFFF"><input name="phone" type="text" id="phone" size="20"/></td>
    </tr>
    <tr>
      <td align="right" bgcolor="#FFFFFF">电子邮箱:</td>
      <td bgcolor="#FFFFFF"><input name="email" type="text" id="member_email" size="20"/></td>
    </tr>
    <tr>
      <td colspan="2" align="center" bgcolor="#FFFFFF"><input type="reset" name="button" id="button" value="重置表单" />
      <input type="submit" name="submit" id="submit" value="确定注册" /></td>
    </tr>
  </table>
</form>
    
<table width="100" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td height="5"></td>
  </tr>
</table>
</body>
</html>